load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

WIREDTIGER_TARGET_COMPATIBLE_WITH = select({
    "//bazel/config:use_wiredtiger_enabled": [],
    "//conditions:default": ["@platforms//:incompatible"],
})

mongo_cc_library(
    name = "storage_wiredtiger_customization_hooks",
    srcs = [
        "wiredtiger_customization_hooks.cpp",
        "wiredtiger_extensions.cpp",
    ],
    hdrs = [
        "wiredtiger_customization_hooks.h",
        "wiredtiger_extensions.h",
    ],
    target_compatible_with = WIREDTIGER_TARGET_COMPATIBLE_WITH,
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:service_context",
    ],
)

idl_generator(
    name = "oplog_truncate_marker_parameters_gen",
    src = "oplog_truncate_marker_parameters.idl",
)

idl_generator(
    name = "wiredtiger_parameters_gen",
    src = "wiredtiger_parameters.idl",
)

idl_generator(
    name = "wiredtiger_global_options_gen",
    src = "wiredtiger_global_options.idl",
)

# This is the smallest possible set of files that wraps WT
mongo_cc_library(
    name = "storage_wiredtiger_core",
    srcs = [
        "oplog_truncate_marker_parameters_gen",
        "wiredtiger_begin_transaction_block.cpp",
        "wiredtiger_compiled_configuration.cpp",
        "wiredtiger_cursor.cpp",
        "wiredtiger_cursor_helpers.cpp",
        "wiredtiger_error_util.cpp",
        "wiredtiger_event_handler.cpp",
        "wiredtiger_global_options.cpp",
        "wiredtiger_index.cpp",
        "wiredtiger_index_util.cpp",
        "wiredtiger_kv_engine.cpp",
        "wiredtiger_oplog_data.cpp",
        "wiredtiger_oplog_manager.cpp",
        "wiredtiger_oplog_truncate_markers.cpp",
        "wiredtiger_parameters.cpp",
        "wiredtiger_parameters_gen",
        "wiredtiger_prepare_conflict.cpp",
        "wiredtiger_record_store.cpp",
        "wiredtiger_recovery_unit.cpp",
        "wiredtiger_session_cache.cpp",
        "wiredtiger_size_storer.cpp",
        "wiredtiger_snapshot_manager.cpp",
        "wiredtiger_stats.cpp",
        "wiredtiger_util.cpp",
    ],
    hdrs = [
        "wiredtiger_begin_transaction_block.h",
        "wiredtiger_compiled_configuration.h",
        "wiredtiger_cursor.h",
        "wiredtiger_cursor_helpers.h",
        "wiredtiger_error_util.h",
        "wiredtiger_event_handler.h",
        "wiredtiger_global_options.h",
        "wiredtiger_index.h",
        "wiredtiger_index_cursor_generic.h",
        "wiredtiger_index_util.h",
        "wiredtiger_kv_engine.h",
        "wiredtiger_oplog_data.h",
        "wiredtiger_oplog_manager.h",
        "wiredtiger_oplog_truncate_markers.h",
        "wiredtiger_prepare_conflict.h",
        "wiredtiger_record_store.h",
        "wiredtiger_recovery_unit.h",
        "wiredtiger_session_cache.h",
        "wiredtiger_session_data.h",
        "wiredtiger_size_storer.h",
        "wiredtiger_snapshot_manager.h",
        "wiredtiger_stats.h",
        "wiredtiger_util.h",
        "//src/mongo/db/catalog:health_log.h",
        "//src/mongo/db/catalog:import_options.h",
        "//src/mongo/db/concurrency:deferred_writer.h",
        "//src/mongo/db/storage:journal_listener.h",
        "//src/mongo/db/storage:snapshot_manager.h",
        "//src/mongo/db/storage/kv:kv_engine.h",
    ],
    target_compatible_with = WIREDTIGER_TARGET_COMPATIBLE_WITH,
    deps = [
        "storage_wiredtiger_customization_hooks",
        "//src/mongo/db:commands",
        "//src/mongo/db:global_settings",
        "//src/mongo/db:mongod_options",
        "//src/mongo/db:prepare_conflict_tracker",
        "//src/mongo/db:record_id_helpers",
        "//src/mongo/db:server_base",
        "//src/mongo/db:server_feature_flags",
        "//src/mongo/db:service_context",
        "//src/mongo/db:snapshot_window_options",
        "//src/mongo/db/catalog:health_log_interface",
        "//src/mongo/db/catalog/validate:validate_options",
        "//src/mongo/db/concurrency:exception_util",
        "//src/mongo/db/query/bson:dotted_path_support",
        "//src/mongo/db/repl:repl_settings",
        "//src/mongo/db/stats:resource_consumption_metrics",
        "//src/mongo/db/storage:backup_block",
        "//src/mongo/db/storage:capped_snapshots",
        "//src/mongo/db/storage:index_entry_comparison",
        "//src/mongo/db/storage:record_store_base",
        "//src/mongo/db/storage:recovery_unit_base",
        "//src/mongo/db/storage:storage_file_util",
        "//src/mongo/db/storage:storage_options",
        "//src/mongo/db/storage:storage_repair_observer",
        "//src/mongo/db/storage/key_string",
        "//src/mongo/util:elapsed_tracker",
        "//src/mongo/util:log_and_backoff",
        "//src/mongo/util:processinfo",
        "//src/third_party/snappy",
        "//src/third_party/wiredtiger",
        "//src/third_party/zlib",
    ],
)

mongo_cc_library(
    name = "storage_wiredtiger",
    srcs = [
        "wiredtiger_global_options_gen",
        "wiredtiger_init.cpp",
        "wiredtiger_options_init.cpp",
        "wiredtiger_server_status.cpp",
    ],
    hdrs = [
        "wiredtiger_server_status.h",
    ],
    target_compatible_with = WIREDTIGER_TARGET_COMPATIBLE_WITH,
    deps = [
        "storage_wiredtiger_core",
        "storage_wiredtiger_customization_hooks",
        "//src/mongo/db/commands:server_status_core",
        "//src/mongo/db/storage:storage_engine_common",
        "//src/mongo/db/storage:storage_engine_impl",
        "//src/mongo/db/storage:storage_engine_lock_file",
        "//src/mongo/db/storage:storage_engine_metadata",
        "//src/mongo/db/storage:storage_options",
        "//src/mongo/util/options_parser",
    ],
)

mongo_cc_library(
    name = "wiredtiger_record_store_test_harness",
    srcs = [
        "wiredtiger_record_store_test_harness.cpp",
    ],
    hdrs = [
        "wiredtiger_record_store_test_harness.h",
    ],
    deps = [
        ":storage_wiredtiger_core",
        "//src/mongo/db:service_context_test_fixture",
        "//src/mongo/db/repl:replmocks",
        "//src/mongo/db/storage:record_store_test_harness",
        "//src/mongo/util:clock_source_mock",
    ],
)

mongo_cc_library(
    name = "wiredtiger_index_test_harness",
    srcs = [
        "wiredtiger_index_test_harness.cpp",
    ],
    hdrs = [
        "//src/mongo/db/catalog:collection_mock.h",
    ],
    deps = [
        "storage_wiredtiger_core",
        "//src/mongo/db:service_context_non_d",
        "//src/mongo/db:service_context_test_fixture",
        "//src/mongo/db/index:index_access_method",
        "//src/mongo/db/storage:sorted_data_interface_test_harness",
    ],
)

mongo_cc_unit_test(
    name = "storage_wiredtiger_test",
    srcs = [
        "wiredtiger_c_api_test.cpp",
        "wiredtiger_error_util_test.cpp",
        "wiredtiger_init_test.cpp",
        "wiredtiger_kv_engine_test.cpp",
        "wiredtiger_prepare_conflict_test.cpp",
        "wiredtiger_recovery_unit_test.cpp",
        "wiredtiger_session_cache_test.cpp",
        "wiredtiger_size_storer_test.cpp",
        "wiredtiger_stats_test.cpp",
        "wiredtiger_util_test.cpp",
    ],
    tags = ["mongo_unittest_fourth_group"],
    deps = [
        ":storage_wiredtiger",
        ":storage_wiredtiger_core",
        "//src/mongo/db:service_context_d_test_fixture",
        "//src/mongo/db:snapshot_window_options",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/index:index_access_method",
        "//src/mongo/db/repl:repl_coordinator_interface",
        "//src/mongo/db/repl:replmocks",
        "//src/mongo/db/storage:checkpointer",
        "//src/mongo/db/storage:recovery_unit_test_harness",
        "//src/mongo/db/storage:storage_engine_common",
        "//src/mongo/db/storage:storage_engine_metadata",
        "//src/mongo/db/storage:storage_options",
        "//src/mongo/db/storage/kv:kv_engine_test_harness",
        "//src/mongo/util:clock_source_mock",
    ],
)

mongo_cc_unit_test(
    name = "storage_wiredtiger_record_store_and_index_test",
    srcs = [
        "wiredtiger_index_test.cpp",
        "wiredtiger_record_store_test.cpp",
        "wiredtiger_standard_index_test.cpp",
        "wiredtiger_standard_record_store_test.cpp",
    ],
    tags = ["mongo_unittest_third_group"],
    deps = [
        ":storage_wiredtiger_core",
        ":wiredtiger_index_test_harness",
        ":wiredtiger_record_store_test_harness",
        "//src/mongo/db:multitenancy",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/storage:oplog_truncation",
        "//src/mongo/db/storage:sorted_data_interface_tests",
    ],
)
